package recommenRatings.domain;

import java.util.List;
import java.util.Map;

import recommenRatings.data.JDBCMessageDAO;
import recommenRatings.data.JDBCUserDAO;

public class MessageManager {

	private String user;
	private List<Message> messages;
	private Map<String,String> friends;
	private int unreadMsg = 0;

	public MessageManager(String currentUser) {
		JDBCUserDAO ju = new JDBCUserDAO();
		JDBCMessageDAO jm = new JDBCMessageDAO();
		user = currentUser;
		
		messages = jm.selectAllMsg(user);
		friends = ju.selectAllFriends(currentUser);
		int auxCount = 0;
		
		for (Message aux : messages) {
			if (!(aux.isRead())) {
				auxCount++;
			}
		}
		unreadMsg = auxCount;
	}
	
	public boolean sendMessage (Message m){
		JDBCMessageDAO jm = new JDBCMessageDAO();
		
		return jm.insert(m);
		
	}
	public void markAsRead(String s){
		JDBCMessageDAO ju = new JDBCMessageDAO();
		ju.markAsRead(s);
	}
	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public List<Message> getMessages() {
		return messages;
	}

	public void setMessages(List<Message> messages) {
		this.messages = messages;
	}

	public Map<String,String> getFriends() {
		return friends;
	}

	public void setFriends(Map<String,String> friends) {
		this.friends = friends;
	}

	public int getUnreadMsg() {
		return unreadMsg;
	}

	public void setUnreadMsg(int unreadMsg) {
		this.unreadMsg = unreadMsg;
	}
	public void deleteMessage(String id){
		JDBCMessageDAO ju = new JDBCMessageDAO();
		ju.delete(id);
	}

}
